#ifndef _IDL_TYPESUPPORT_H_INCLUDED_ 
#define _IDL_TYPESUPPORT_H_INCLUDED_

#include <string>
using std::string;
#include "IDL_DataWriter.h"
#include "IDL_DataReader.h"
#include "DDS/TypeSupport.h"

#include "DDS/DomainParticipant.h"
class DomainParticipant;

list<string> ListData;
static void initList()
{	if (ListData.size() <= 0)
	{
		ListData.push_back("struct TestData{");
		ListData.push_back("sequence<octet> payload;");
		ListData.push_back("string 32 md5;");
		ListData.push_back("unsignedlonglong seq_num;");
		ListData.push_back("unsignedlonglong send_time;");
		ListData.push_back("};");
	}
}

class TestDataTypeSupport : public TypeSupport {
public:
	static TestData* create_data()
	{
		return new TestData;
	}

	static ReturnCode_t delete_data(TestData* pTestData)
	{
		delete pTestData;
		pTestData = NULL;
		return ReturnCode_t();
	}

	static void print_data(TestData* pTestData,int layer = 0)
	{
		char *c = new char[layer];
		int i = 0;
		for (; i < layer; i++)
		{
			c[i] = '\t';
		}
		c[i] = '\0';
		std::cout<<c<<"TestData:"<<std::endl;
		int num_payload= 0;
		num_payload = pTestData->payload.length();
		std::cout<<c<<"  maximum:"<<pTestData->payload.get_maximum()<<std::endl;
		std::cout<<c<<"  length:"<<num_payload<<std::endl;
		layer++;
		for(int iSeq1=0;iSeq1<num_payload;iSeq1++)
		{
				std::cout<<c<<"  payload["<<iSeq1<<"]: "<<pTestData->payload[iSeq1]<<std::endl;
		}
		layer--;
		std::cout<<c<<"  md5 = "<< pTestData->md5 <<std::endl;
		std::cout<<c<<"  seq_num = "<< pTestData->seq_num <<std::endl;
		std::cout<<c<<"  send_time = "<< pTestData->send_time <<std::endl;
	}

	static const char* get_type_name()
	{
		return "TestData";
	}

	static int register_type(DomainParticipant* participant, string type_name)
	{
		if (type_name.empty())
			type_name = get_type_name();

		initList();
		return participant->register_type(type_name,ListData);
	}
};

#endif
